﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Wpf;
using System.Windows.Threading;
using log4net;
using Avalon.Windows.Controls;
using System.Windows.Controls;
using OpenExpressApp.Module.WPF;
using System.Windows;

namespace OpenExpressApp.WPF.Controls
{
    /// <summary>
    /// 在CslaDataProvider的基础上增加了： 错误处理。
    /// </summary>
    public class GCslaDataProvider : CslaDataProvider
    {
        private void ShowError(Exception error)
        {
            error.ShowError();
        }

        protected override void OnQueryFinished(object newData, Exception error, DispatcherOperationCallback completionWork, object callbackArguments)
        {
            base.OnQueryFinished(newData, error, completionWork, callbackArguments);
            if (null != error)
            {
                ILog log = log4net.LogManager.GetLogger("OpenExpressApp");
                log.Error("CSLADataProvider获取数据报错", error);
                Application.Current.Dispatcher.Invoke(new DoShowError(ShowError), error);
            }
        }

        /// <summary>
        /// 临时的委托，用于Dispatcher.Invoke方法。
        /// </summary>
        /// <param name="error"></param>
        private delegate void DoShowError(Exception error);
    }
}
